/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author AungPaing
 */
@WebServlet ("/Register")
public class sevlet extends HttpServlet {
    
    String btn=null;
    String btn1=null;
    @Override
    protected void doPost(HttpServletRequest request,HttpServletResponse response)
            throws ServletException, IOException
    {
        
        btn=request.getParameter("btnsave");
        btn1=request.getParameter("btnsubmit");
         //boolean result=(boolean)request.getAttribute("chkrn");
        if(btn!=null)
        {
        Cookie Cname=new Cookie("Cname",request.getParameter("txtName"));
        response.addCookie(Cname);
        Cookie Cemail=new Cookie("Cemail",request.getParameter("txtemail"));
        response.addCookie(Cemail);
        Cookie Cchknew=new Cookie("rn",request.getParameter("chkrn"));
        Cookie country=new Cookie("cn",request.getParameter("country"));
        Cookie Cchkfood=new Cookie("food",request.getParameter("chkfood"));
        Cookie Cchkmovie=new Cookie("movie",request.getParameter("chkmovie"));
        Cookie CchkSport=new Cookie("Sport",request.getParameter("chksport"));
        Cookie Crdogender=new Cookie("gender",request.getParameter("rdogender"));
        
        }
        if(btn1 != null )
        {
        String name=request.getParameter("txtName");
        String email=request.getParameter("txtemail");
        String chknew=request.getParameter("chkrn");
        String comcountry=request.getParameter("country");
        response.setStatus(HttpServletResponse.SC_CREATED);//status
        response.setContentType("text/html");//header 
       
      try( PrintWriter out = response.getWriter()){
       out.println("Thank you for registering with us ");
       
      if(!chknew.equals(""))
       {
         if(!name.equals("")&& !email.equals("") && !comcountry.equals(""))
         {
        out.println(" Our monthly newsletter on "+name+""+email+""+comcountry+"will be send to your fred@gmail.com" );
         }
         else
             out.println("Our monthly newsletter on");
       }
        out.flush();
        
       // Cookie ck=new 
      }
      }
    }
}
 